#!/bin/bash -l

## Choix du compilo : openmpi ou intel 
export COMPILO="OpenMPI"
#export COMPILO="Intel"

if [ "$1" == "Intel" ]
then
    export COMPILO="Intel"
fi 

## openmpi et compilateur gnu c++
export OUTPUT_FILE=../bin/ompi-samebatch-multiproduct-binpacking
export MPICC_CMD="mpic++"

#export MPICC_PARAM="-DGMPI -DGMPIDEBUG"
export MPICC_PARAM="-DGMPI "

export MPICC_OPTIM_PARAM="-O3"

if (( `hostname` == "pc-gi-90" || `hostname` == "eman" || `hostname` == "pcp-set-26" ))
then
    echo Computer `hostname`
    echo Compiler ${COMPILO}
else
    echo Computer mesocluster
    echo Compiler ${COMPILO}

    export MPICC_PARAM="${MPICC_PARAM} -DMPICH_IGNORE_CXX_SEEK"

    module rm ompi
    if [ "${COMPILO}" == "OpenMPI" ]
    then 
        echo module load ompi
        module load ompi
    else
        ## compilateur intel 
        export MPICC_CMD="mpiicc" 
        export OUTPUT_FILE=../bin/mpii-samebatch-multiproduct-binpacking
    fi
fi

# COMPILATION OPTIMALE
export MPICC_PARAM="${MPICC_PARAM} ${MPICC_OPTIM_PARAM} -w -o ${OUTPUT_FILE}"

# COMPILATION AVEC DEBUG
#export MPICC_PARAM="${MPICC_PARAM} -g -o ${OUTPUT_FILE}"

# script pouvant etre executer depuis le repertoire parent par 
# la commande script/compilempi
# ou depuis le repertoire src (pour emacs, commande M-x compile)
if [ -d "src" ]; then
    cd src
fi

pwd
echo ${MPICC_CMD} ${MPICC_PARAM} *.cpp
${MPICC_CMD} ${MPICC_PARAM} *.cpp

